<?php
include_once ('model/Student/class-student.php');
include_once ('model/Staff/class-course.php');
include_once ('model/Staff/class-trainningitem.php');
include_once ('control/student-proc.php');
session_start();

$student;
if(!isset($_SESSION["user"])){
    header("location:http:/educational/index.php");
} else {
	$student = $_SESSION["user"];
	include ('model/connect.php');
}

function renderMarkHeader($semester,$isFirst) {
	if(!$isFirst) { echo "</table><br/>" ;}
	?>
    <table>
  	<thead>
     <tr><th colspan="4" style="font-size:16px;">Học kỳ&nbsp;<?php echo $semester;?></th></tr>	
     <tr>
    	<th>Mã môn</th>
        <th>Tên môn</th>
        <th>Điểm trung bình (hệ 10)</th>
        <th>Điểm trung bình</th>
      </tr>  
    </thead>
    <?php
}
?>
<!DOCTYPE html>
<html xml:lang="EN" lang="EN" dir="ltr">
<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Educational</title>
<?php include("header-srcipt.php");?>
</head>
<body>
<div class="wrapper col0">
  <div id="topbar">
  	<div id="loginpanel">
      <ul>
        <li class="left">Welcome <?php echo($student->getStudentName());?> </li>
      </ul>
    </div>
    <br class="clear" />
  </div>
</div>
<!-- ####################################################################################################### -->
<?php include("header-title.php");?>
<!-- ####################################################################################################### -->
<?php include("student-menu-main.php");?>
<!-- ####################################################################################################### -->
<div class="wrapper col4">
  <div id="container">  
    <?php 
		$lastSem = 0;
		$currSem = 0;
		foreach($student->getAttendance() as $att) { 
			$lastSem = $currSem;
			$currSem = $att->getSemester();
			if($currSem != $lastSem) {
				if($lastSem == 0)
					renderMarkHeader($currSem,true);
				else 
					renderMarkHeader($currSem,false);	
			}
	?>
    <tr>
    	<td><?php echo($att->getCourseId()); ?></td>
        <td width="350"><?php echo(lookupCoursename($att->getCourseId())); ?></td>
        <td><?php echo($att->getFinalGrade()); ?></td>
        <td><?php echo(calGrade($att->getFinalGrade())); ?></td>
    </tr>
    <?php } ?>
  </table>
  </div>
</div>
<!-- ####################################################################################################### -->
<?php include("footer.php");?>
</body>
</html>
